import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import livereload from "rollup-plugin-livereload";
import serve from "rollup-plugin-serve";
import { terser } from "rollup-plugin-terser";

// 根据不同环境使用不同插件
const plugins =
  process.env.NODE_ENV === "development"
    ? [
        resolve(),
        commonjs(),
        serve({
          host: "localhost",
          port: 6600,
        }),
        livereload("dist"), // 监听 dist 目录下的变化
      ]
    : [
        resolve(),
        commonjs(),
        terser(), // 压缩混淆
      ];

export default {
  input: "src/index.js", // 你的入口文件
  output: [
    {
      // TODO 配置项 https://cn.rollupjs.org/configuration-options/#output-format
      file: "dist/bundle.module.js", // 打包后的文件
      format: "es", // es模块化导出
    },
  ],
  plugins,
  watch: {
    clearScreen: false, // 清除控制台屏幕
  },
};
